/////////////////////////////////////////////////////////
//                                                     //
// Copyright (c) 2016年 上证云平台. All rights reserved. //
//                                                     //
/////////////////////////////////////////////////////////


#import "MainViewController.h"
#import "ResponseViewController.h"
#import "MApi.h"
#import "OHLCViewController.h"
#import "TrendChartViewController.h"
#import "RequestViewController.h"

#define LEVELS @[@"Level-1",@"Level-2"]

@interface MainViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSArray *infos;
@property (nonatomic, weak) IBOutlet UITableView *tableView;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - private


#pragma mark - lazy loading


#pragma mark - tableView dataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return LEVELS.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    cell.textLabel.text = LEVELS[indexPath.row];
    return cell;
}


#pragma mark- tableView delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {       [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *fileName = LEVELS[indexPath.row];
    NSString *filePath = [[NSBundle mainBundle]pathForResource:fileName ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    NSArray *infos = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    RequestViewController *vc = [[RequestViewController alloc]init];
    if ([fileName isEqualToString:@"Level-1"]) {
        vc.level = MApiSourceLevel1;
    }else if ([fileName isEqualToString:@"Level-2"]) {
        vc.level = MApiSourceLevel2;
    }
    vc.infos = infos;
    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark - UIAlertViewDelegate


@end
